package com.hui.web.servlet.studentServlet;

import com.hui.bean.ClassBean;
import com.hui.bean.RoomBean;
import com.hui.service.IClassService;
import com.hui.service.IRoomService;
import com.hui.service.impl.ClassServiceImpl;
import com.hui.service.impl.RoomServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 *
 * 添加学生界面控制跳转，预处理班级和房间
 *
 *
 */
@WebServlet(name = "StudentAddIndexServlet",urlPatterns = "/student/add/index")

public class StudentAddIndexServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        IClassService classService=new ClassServiceImpl();
        List<ClassBean> allClasses = classService.getAllClasses();
        request.setAttribute("allClasses",allClasses);

        IRoomService roomService=new RoomServiceImpl();
        List<RoomBean> canInRooms = roomService.getCanInRoomsByRoomType("M");
        request.setAttribute("canInRooms",canInRooms);

        request.getRequestDispatcher("/page/student/studentin.jsp").forward(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
